/*******************************************************************************
 * Copyright (c) 2012 March and Conquest.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package mrusanov.towers.main.ui;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import mrusanov.towers.resources.Resource;

public class ResourceComponent extends JPanel {
	private static final long serialVersionUID = 2407270940198243608L;

	private int income;
	private int count;

	private JLabel incomeLabel;
	private JLabel countLabel;

	public ResourceComponent(Resource resource) {
		setLayout(new GridLayout(3, 1));

		incomeLabel = new JLabel();
		incomeLabel.setFont(MainForm.BOLD_FONT);
		incomeLabel.setHorizontalAlignment(SwingConstants.CENTER);
		incomeLabel.setForeground(getColor(resource));

		countLabel = new JLabel();
		countLabel.setFont(MainForm.BOLD_FONT);
		countLabel.setHorizontalAlignment(SwingConstants.CENTER);
		countLabel.setForeground(getColor(resource));

		JLabel incomeNameLabel = new JLabel(resource.getLocalizedIncomeName());
		incomeNameLabel.setFont(MainForm.BOLD_FONT);
		incomeNameLabel.setVerticalAlignment(SwingConstants.TOP);
		incomeNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
		incomeNameLabel.setForeground(getColor(resource));

		add(incomeNameLabel);
		add(incomeLabel);
		add(countLabel);

		setBorder(BorderFactory.createRaisedBevelBorder());
	}

	public void setIncome(int income) {
		this.income = income;
		incomeLabel.setText(" +" + this.income);
	}

	public void setCount(int count) {
		this.count = count;
		countLabel.setText(" " + this.count);
	}

	public Color getColor(Resource resource) {
		switch (resource) {
			case BEASTS:
				return new Color(0x006A4E);
			case BRICKS:
				return Color.RED;
			case GEMS:
				return Color.BLUE;
			default:
				throw new IllegalArgumentException("Unknown resource: " + resource);
		}
	}
}
